import { getUserInfo } from '@/common/index'

const state = () => ({
    userInfo: getUserInfo(),
    roleData: {},
    roleDataList: [
        {
            label: '总裁',
            value: 'USER_LEVEL_CEO'
        },{
            label: '事业部',
            value: 'USER_LEVEL_DIVISION'
        },{
            label: '大区',
            value: 'USER_LEVEL_BIG'
        },{
            label: '营业区',
            value: 'USER_LEVEL_SMALL'
        },{
            label: '营业部',
            value: 'USER_LEVEL_SALES_DEPARTMENT'
        }
    ],
    roleDataMap: {
        'USER_LEVEL_CEO': '总部',
        'USER_LEVEL_HEADQUARTERS': '经营本部',
        'USER_LEVEL_DIVISION': '事业部',
        'USER_LEVEL_BIG': '大区',
        'USER_LEVEL_SMALL': '营业区',
        'USER_LEVEL_SALES_DEPARTMENT': '营业部'
    },
    roleDataCodeMap: {
        '总部': 'USER_LEVEL_CEO',
        '经营本部': 'USER_LEVEL_HEADQUARTERS',
        '事业部': 'USER_LEVEL_DIVISION',
        '大区': 'USER_LEVEL_BIG',
        '营业区': 'USER_LEVEL_SMALL',
        '营业部': 'USER_LEVEL_SALES_DEPARTMENT'
    },
    deptLevelMap: {
        2: 'USER_LEVEL_CEO',
        4: 'USER_LEVEL_DIVISION',
        5: 'USER_LEVEL_BIG',
        6: 'USER_LEVEL_SMALL',
        7: 'USER_LEVEL_SALES_DEPARTMENT'
    }
})

const getters = {
}

const actions = {
    setUserInfo({commit}, data){
        commit('setUserInfo', data)
    },
    setRoleData({commit}, data){
        commit('setRoleData', data)
    },
}

const mutations = {
    setUserInfo(state, data){
        //const userInfo = Object.assign(state.userInfo || getUserInfo(), data);
        localStorage.setItem('userInfo', JSON.stringify(data));
        state.userInfo = data;
    },
    setRoleData(state, data){
        state.roleData = data;
    },
}

export default {
    state,
    getters,
    actions,
    mutations
}
